import request from '../utils/request'

import API from './api'

// 获取商品分类
export const getInventories = () => request({
  url: API.INVENTORIES_API,
  method: 'GET',
})

// 获取所有商品的总数
export const getStocks = ({...options} = {}) => request({
  url: API.STOCKS_API,
  method: 'GET',
  params: {
    ...options,
  },
}).then((data) => data.length)
  .catch((err) => {
    console.log(err)
  })

// 根据分页数据获取当页商品数据
// 废弃
export const getStocksPageList = ({_page, _limit} = {}) => request({
  url: API.STOCKS_API,
  method: 'GET',
  params: {
    _page,
    _limit,
  },
})

// 查询商品数据终极版
export const getStocksUltimate = ({_page = 1, _limit = 3, ...otherOptions} = {}) => request({
  url: API.STOCKS_API,
  method: 'GET',
  params: {
    _page,
    _limit,
    ...otherOptions,
  },
})

// 修改商品数据
export const updateStockOfCell = (id, {...options} = {}) => request({
  url: API.STOCKS_API + '/' + id,
  method: 'PATCH',
  data: {
    ...options,
  },
})

// 获取指定商品数据
export const getStocksWithID = (id) => request({
  url: API.STOCKS_API + '/' + id,
  method: 'GET',
})

// 添加库存
export const addStockData = ({...options} = {}) => request({
  url: API.STOCKS_API,
  method: 'POST',
  data: {
    ...options,
  },
})

// 获取数量小于等于指定数量的商品数据
export const getStocksTipsData = (amount_lte) => request({
  url: API.STOCKS_API,
  method: 'GET',
  params: {
    amount_lte,
  },
})
